const merge = require('webpack-merge');
const common = require('./webpack.base.js');
const path = require('path');
const webpack =require('webpack');  
const CopyWebpackPlugin = require('copy-webpack-plugin')
//清理
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractTextWebapckPlugin = require('extract-text-webpack-plugin');  //引入插件
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const config =require('./config.js');
module.exports = merge(common, {
	mode: 'production',
	devtool: '',
	output: {
	    path: config.prod.assetsSubPath,
		filename:config.prod.filename,
		publicPath:config.prod.assetsPublicPath,//解析目录相对于Html引用
	},
    module:{
        rules:[
            {
				test:/\.vue$/,
				loader:'vue-loader',
				options:{
					hotReload: true, // 热重载	
					loaders:{
						css:ExtractTextWebapckPlugin.extract({
							use:['vue-style-loader!css-loader']
						}),
						less:ExtractTextWebapckPlugin.extract({
							use:['vue-style-loader!css-loader!less-loader']
						})
					}
				}
            },
            {
				test:/\.(less|css)$/,
				use: ExtractTextWebapckPlugin.extract({
                    use: ['css-loader', 'less-loader'],
                    fallback: 'style-loader'
                })
            }
        ]
    },
    plugins:[
		
        new ExtractTextWebapckPlugin('style/style.[name].css'),
        new CleanWebpackPlugin(['../dist/*'],{watch:true}),//删除目录
        // new webpack.optimize.CommonsChunkPlugin({
		// 	name: 'vender',
		// 	minChunks: Infinity
		// }),
		new CompressionPlugin(),
		new CopyWebpackPlugin([
			{
			  from: path.resolve(__dirname, '../static'),
			  to: config.prod.assetsSubDirectory,
			  ignore: ['.*']// 忽略文件
			}
		])
    ],optimization:{
		minimizer: [new UglifyJsPlugin({
			test: /\.js(\?.*)?$/i,
			cache: true
		})],
		splitChunks: {
	       chunks: 'all'
		}
	}
  
});